package logic.ships.resourceShip;

import java.util.List;

import logic.common.team.Team;
import logic.nodes.collision.DummyType;
import logic.ships.moveableShip.MovableShip;
import logic.ships.moveableShip.MovableShipProperties;

import com.jme.math.Vector3f;
import com.jme.scene.Node;

public abstract class ResourceShip extends MovableShip {
	
	private static final long serialVersionUID = 1L;
	
	protected List<ResourceSlot> resourceSlots;
	
	public ResourceShip(String modelPath, String title, Node model, MovableShipProperties properties, 
			Team team, boolean initNozzles, DummyType dummyType) {
		super(modelPath, title, model, properties, team, initNozzles, dummyType);
		
		ResourceSlotCreator slotCreator = new ResourceSlotCreator(this);
		resourceSlots = slotCreator.getResourceSlots();
	}
	
	public void dropResource(float amount) {
		assert(amount > 0f);
		team.addTeamMoney(amount);
	}
	
	public ResourceSlot getNearestResourceSlot(Vector3f pos) {
		float minDist = Float.POSITIVE_INFINITY;
		ResourceSlot nearestSlot = null;
		for(ResourceSlot slot : resourceSlots) {
			if(slot.getMoveLocation() == null) continue;
			float dist = slot.getMoveLocation().distance(pos);
			if(dist < minDist) {
				nearestSlot = slot;
				minDist = dist;
			}
		}
		return nearestSlot;
	}
}